const gulp = require('gulp');
const webpack = require('webpack-stream');
const clean = require('gulp-clean');
let pump = require('pump');

/*
* 快捷提示:
    * 开发构建: gulp clean redirect spa mobile file_upload_fileUpload file_upload_register
    * 生产构建: gulp clean-prod redirect-prod spa-prod mobile-prod file_upload_fileUpload-prod file_upload_register-prod
    * 统一格式:在开发构建的任务指令后面加上"-prod"即可转换成生成构建
* */
/*
* task说明:
* clean: 清理指定文件夹
* redirect: 构建重定向页面
* spa: 构建单页SPA
* mobile: 构建移动页面
* file_upload_fileUpload: 构建文件上传页面
* file_upload_register: 构建文件上传登陆页面
* */

/*事实上,不需要为开发构建和生产构建单独创建文件夹*/
/*2018.3.7 现在也没有时间去修正了,以后再说吧*/
let dist = './dist_prod';
let dist_prod = './dist_prod';

gulp.task('clean', function(cb) {
    pump([
        gulp.src(dist),
        clean()
    ], cb)
});

gulp.task('clean-prod', function(cb) {
    pump([
        gulp.src(dist_prod),
        clean()
    ], cb)
});

gulp.task('spa-prod',function () {
    /*上线服务器用,会压缩js*/
    gulp.src(('../spa/entry_kfm_spa.js'))
        .pipe(webpack(require('./spa.webpack.prod.js')))
        .pipe(gulp.dest((dist_prod)));
});

gulp.task('spa',function () {
    /*开发用*/
    gulp.src('../spa/entry_kfm_spa.js')
        .pipe(webpack(require('./spa.webpack.config.js')))
        .pipe(gulp.dest(dist));
});

gulp.task('redirect',function () {
    /*
    * redirect页面的build
    * */
    gulp.src('../redirect_entry.js')
        .pipe(webpack(require('./redirect.webpack.config.js')))
        .pipe(gulp.dest(dist));
});

gulp.task('redirect-prod',function () {
    /*
    * redirect页面的build
    * */
    gulp.src('../redirect_entry.js')
        .pipe(webpack(require('./redirect.webpack.prod.js')))
        .pipe(gulp.dest(dist_prod));
});

gulp.task('mobile',function () {
    /*
    * 移动端build
    * */
    gulp.src('../kfm_mobile/entry_mobile.js').
    pipe(webpack(require('./mobile.index.webpack.config.js'))).
    pipe(gulp.dest((dist)));

    gulp.src('../kfm_mobile/QianDuanJiShi/entry_recordEvent.js').
    pipe(webpack(require('./mobile.qdjs.webpack.config.js'))).
    pipe(gulp.dest(dist));

    gulp.src('../kfm_mobile/QianDuanYuanMa/entry_source_code.js').
    pipe(webpack(require('./mobile.qdym.webpack.config.js'))).
    pipe(gulp.dest(dist));

});

gulp.task('mobile-prod',function () {
    /*
    * 移动端build
    * */
    gulp.src('../kfm_mobile/entry_mobile.js').
    pipe(webpack(require('./mobile.index.webpack.prod.js'))).
    pipe(gulp.dest((dist_prod)));

    gulp.src('../kfm_mobile/QianDuanJiShi/entry_recordEvent.js').
    pipe(webpack(require('./mobile.qdjs.webpack.prod.js'))).
    pipe(gulp.dest(dist_prod));

    gulp.src('../kfm_mobile/QianDuanYuanMa/entry_source_code.js').
    pipe(webpack(require('./mobile.qdym.webpack.prod.js'))).
    pipe(gulp.dest(dist_prod));

});

gulp.task('file_upload_register',function () {
    /*
    * 登陆页面构建
    * */
    gulp.src( '../file_upload/src/register_entry.js')
        .pipe(webpack(require('./fileUpload.register.webpack.config.js')))
        .pipe(gulp.dest(dist));
});

gulp.task('file_upload_register-prod',function () {
    /*
    * 后台登陆页面构建
    * */
    gulp.src( '../file_upload/src/register_entry.js')
        .pipe(webpack(require('./fileUpload.register.webpack.prod.js')))
        .pipe(gulp.dest(dist_prod));
});

gulp.task('file_upload_fileUpload',function () {
    /*
    * 上传页面构建
    * */

    gulp.src('../file_upload/src/file_upload_entry/file_upload_entry.js')
        .pipe(webpack(require('./fileUpload.fileUpload.webpack.config.js')))
        .pipe(gulp.dest(dist))
});

gulp.task('file_upload_fileUpload-prod',function () {
    /*
    * 上传页面构建
    * */

    gulp.src('../file_upload/src/file_upload_entry/file_upload_entry.js')
        .pipe(webpack(require('./fileUpload.fileUpload.webpack.prod.js')))
        .pipe(gulp.dest(dist_prod))
});




